﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;

namespace WMS.FC.Infrastructure.Register
{
    public static class SwaggerRegister
    {
        public static void RegisterSwagger(this WebApplicationBuilder builder, string baseDirectory)
        {
            builder.Services.AddSwaggerGen(options =>
            {
                options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "请输入token",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Type = SecuritySchemeType.ApiKey,
                    BearerFormat = "JWT",
                    Scheme = "Bearer"
                });

                options.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme()
                        {
                            Reference=new OpenApiReference()
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id="Bearer"
                            }
                        },new List<string>()
                    }
                });

                options.IncludeXmlComments(Path.Combine(baseDirectory, "WMS.FC.WebApi.xml"), true);
            });
        }
    }
}
